<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Annotation | lilei</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/images/icons/logo.png">
    <link rel="apple-touch-icon" href="/images/icons/logo.png">
    <link rel="manifest" href="/manifest.json">
    <script type="text/javascript" src="/assets/js/load.js"></script>
    <meta name="description" content="个人网站">
    <meta name="twitter:title" content="Annotation">
    <meta name="twitter:description" content="">
    <meta name="twitter:card" content="summary">
    <meta name="twitter:url" content="http://www.lileiblog.xyz/Java/Annotation.html">
    <meta property="og:type" content="article">
    <meta property="og:title" content="Annotation">
    <meta property="og:description" content="">
    <meta property="og:url" content="http://www.lileiblog.xyz/Java/Annotation.html">
    <meta property="og:site_name" content="lilei">
    <meta itemprop="name" content="Annotation">
    <meta itemprop="description" content="">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/images/icons/logo.png">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="keywords" content="lilei,vue,vuepress,vuepress-theme,theme,主题,vuepress主题,blog
        ,vuepress-blog,java,python,shell,sql,golang,script,shell script,nginx,windows,去广告,androd,google drive
        ,one drive,idea,eclipse,git,小程序">
    <meta name="referrer" content="never">
    
    <link rel="preload" href="/assets/css/0.styles.8932179b.css" as="style"><link rel="preload" href="/assets/js/app.269009d6.js" as="script"><link rel="preload" href="/assets/js/3.974b9720.js" as="script"><link rel="preload" href="/assets/js/24.43e324e1.js" as="script"><link rel="prefetch" href="/assets/js/10.5915e99b.js"><link rel="prefetch" href="/assets/js/11.ff732762.js"><link rel="prefetch" href="/assets/js/12.8bb86d91.js"><link rel="prefetch" href="/assets/js/13.18bde5b0.js"><link rel="prefetch" href="/assets/js/14.314fae34.js"><link rel="prefetch" href="/assets/js/15.0a4ff48f.js"><link rel="prefetch" href="/assets/js/16.ffaf1503.js"><link rel="prefetch" href="/assets/js/17.49a31a6e.js"><link rel="prefetch" href="/assets/js/18.7e6443bf.js"><link rel="prefetch" href="/assets/js/19.6880cc9a.js"><link rel="prefetch" href="/assets/js/20.1fb3f255.js"><link rel="prefetch" href="/assets/js/21.0cd39eea.js"><link rel="prefetch" href="/assets/js/22.392d85cb.js"><link rel="prefetch" href="/assets/js/23.f50adb15.js"><link rel="prefetch" href="/assets/js/25.e3663205.js"><link rel="prefetch" href="/assets/js/26.da141fb8.js"><link rel="prefetch" href="/assets/js/27.6c05235a.js"><link rel="prefetch" href="/assets/js/28.c124245a.js"><link rel="prefetch" href="/assets/js/29.d185870d.js"><link rel="prefetch" href="/assets/js/30.8587d422.js"><link rel="prefetch" href="/assets/js/31.dc382b56.js"><link rel="prefetch" href="/assets/js/32.20ba32e9.js"><link rel="prefetch" href="/assets/js/33.6ecd7de9.js"><link rel="prefetch" href="/assets/js/34.2b91c13a.js"><link rel="prefetch" href="/assets/js/35.66ed0733.js"><link rel="prefetch" href="/assets/js/36.ce7bca84.js"><link rel="prefetch" href="/assets/js/37.d00bb5ac.js"><link rel="prefetch" href="/assets/js/38.c3ecbb6f.js"><link rel="prefetch" href="/assets/js/39.308f4175.js"><link rel="prefetch" href="/assets/js/4.520f6ecc.js"><link rel="prefetch" href="/assets/js/40.f4b98bc2.js"><link rel="prefetch" href="/assets/js/41.95fae64f.js"><link rel="prefetch" href="/assets/js/42.fe4f877b.js"><link rel="prefetch" href="/assets/js/43.ca8f222e.js"><link rel="prefetch" href="/assets/js/44.4d4ee79e.js"><link rel="prefetch" href="/assets/js/45.79178b33.js"><link rel="prefetch" href="/assets/js/46.c3817d0b.js"><link rel="prefetch" href="/assets/js/47.b8252443.js"><link rel="prefetch" href="/assets/js/48.df9d5d3b.js"><link rel="prefetch" href="/assets/js/49.d812fdb2.js"><link rel="prefetch" href="/assets/js/5.f1a24a16.js"><link rel="prefetch" href="/assets/js/50.55cfcaa8.js"><link rel="prefetch" href="/assets/js/51.b8608b02.js"><link rel="prefetch" href="/assets/js/52.52c5e00d.js"><link rel="prefetch" href="/assets/js/53.3a9bd5fb.js"><link rel="prefetch" href="/assets/js/54.a4240c13.js"><link rel="prefetch" href="/assets/js/55.01c4b876.js"><link rel="prefetch" href="/assets/js/56.f29549a3.js"><link rel="prefetch" href="/assets/js/57.01438a04.js"><link rel="prefetch" href="/assets/js/58.29bb4626.js"><link rel="prefetch" href="/assets/js/59.e8b89408.js"><link rel="prefetch" href="/assets/js/6.8c478b39.js"><link rel="prefetch" href="/assets/js/60.bedb5381.js"><link rel="prefetch" href="/assets/js/61.bdfbe584.js"><link rel="prefetch" href="/assets/js/62.cb825d1a.js"><link rel="prefetch" href="/assets/js/63.a9516572.js"><link rel="prefetch" href="/assets/js/64.aa854ed7.js"><link rel="prefetch" href="/assets/js/65.285f883d.js"><link rel="prefetch" href="/assets/js/66.12849f37.js"><link rel="prefetch" href="/assets/js/67.c18b00e4.js"><link rel="prefetch" href="/assets/js/68.fa59daa9.js"><link rel="prefetch" href="/assets/js/69.e9d5dda4.js"><link rel="prefetch" href="/assets/js/7.cfb0d0ea.js"><link rel="prefetch" href="/assets/js/70.db126cce.js"><link rel="prefetch" href="/assets/js/71.6acb04cd.js"><link rel="prefetch" href="/assets/js/72.7ff0ab11.js"><link rel="prefetch" href="/assets/js/73.9a66da79.js"><link rel="prefetch" href="/assets/js/74.0a38a030.js"><link rel="prefetch" href="/assets/js/75.7b32dbb3.js"><link rel="prefetch" href="/assets/js/8.cb9c08e5.js"><link rel="prefetch" href="/assets/js/9.ad652cfe.js"><link rel="prefetch" href="/assets/js/vendors~flowchart.110a1065.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8932179b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/images/icons/logo.png" alt="lilei" class="logo"> <span class="site-name can-hide">lilei</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link router-link-active">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/Form/" class="nav-link">
  Form
</a></div><div class="nav-item"><a href="/IDE/" class="nav-link">
  IDE
</a></div><div class="nav-item"><a href="/Java/" class="nav-link router-link-active">
  Java
</a></div><div class="nav-item"><a href="/Other/" class="nav-link">
  Other
</a></div><div class="nav-item"><a href="/Python/" class="nav-link">
  Python
</a></div><div class="nav-item"><a href="/SQL/" class="nav-link">
  SQL
</a></div><div class="nav-item"><a href="/Shell/" class="nav-link">
  Shell
</a></div><div class="nav-item"><a href="/System/" class="nav-link">
  System
</a></div> <a href="https://github.com/woytu/notes-vuepress" target="_blank" rel="noopener noreferrer" class="repo-link">
    GitHub
    <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/Java/" aria-current="page" class="sidebar-link">Java</a></li><li><a href="/Java/Annotation.html" aria-current="page" class="active sidebar-link">Annotation</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/Java/Annotation.html#flag" class="sidebar-link">Flag</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#jdk" class="sidebar-link">JDK</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#servlet" class="sidebar-link">Servlet</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#validation" class="sidebar-link">Validation</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#jax-rs" class="sidebar-link">JAX-RS</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#spring" class="sidebar-link">Spring</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#swagger2" class="sidebar-link">Swagger2</a></li><li class="sidebar-sub-header"><a href="/Java/Annotation.html#jackson" class="sidebar-link">Jackson</a></li></ul></li><li><a href="/Java/JDK安装配置.html" class="sidebar-link">JDK安装配置</a></li><li><a href="/Java/JDK工具.html" class="sidebar-link">JDK工具</a></li><li><a href="/Java/Java构建管理.html" class="sidebar-link">Java构建管理</a></li><li><a href="/Java/Java笔记.html" class="sidebar-link">Java笔记</a></li><li><a href="/Java/ORM.html" class="sidebar-link">ORM</a></li><li><a href="/Java/SPI.html" class="sidebar-link">SPI</a></li><li><a href="/Java/Spring.html" class="sidebar-link">Spring</a></li><li><a href="/Java/Tomcat.html" class="sidebar-link">Tomcat</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="annotation"><a href="#annotation" class="header-anchor">#</a> Annotation</h1> <p></p><div class="table-of-contents"><ul><li><a href="#flag">Flag</a></li><li><a href="#jdk">JDK</a></li><li><a href="#servlet">Servlet</a></li><li><a href="#validation">Validation</a></li><li><a href="#jax-rs">JAX-RS</a></li><li><a href="#spring">Spring</a><ul><li><a href="#声明bean的注解">声明bean的注解</a></li><li><a href="#注入bean的注解">注入bean的注解</a></li><li><a href="#java配置类相关注解">java配置类相关注解</a></li><li><a href="#切面-aop-相关注解">切面（AOP）相关注解</a></li><li><a href="#bean的属性支持">@Bean的属性支持</a></li><li><a href="#value注解">@Value注解</a></li><li><a href="#环境切换">环境切换</a></li><li><a href="#异步相关">异步相关</a></li><li><a href="#定时任务相关">定时任务相关</a></li><li><a href="#enable-注解说明">@Enable*注解说明</a></li><li><a href="#测试相关注解">测试相关注解</a></li><li><a href="#springmvc注解">SpringMVC注解</a></li></ul></li><li><a href="#swagger2">Swagger2</a></li><li><a href="#jackson">Jackson</a></li></ul></div><p></p> <h2 id="flag"><a href="#flag" class="header-anchor">#</a> Flag</h2> <blockquote><p>解释注解的方式：反射！反射是jdk中提供的一种机制，通过读取编译后的运行文件，反向获取类信息的一种手段！可以通过反射获取类、方法、成员变量上的运行时注解内容！</p></blockquote> <blockquote><p>元注解: 能注解到注解上的注解，能用在其他注解上的注解</p></blockquote> <ul><li><a href="https://www.runoob.com/w3cnote/java-annotation.html" target="_blank" rel="noopener noreferrer">Java 注解（Annotation）<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/linton1/article/details/93733508" target="_blank" rel="noopener noreferrer">Javadoc标签和Javadoc注释规范<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <h2 id="jdk"><a href="#jdk" class="header-anchor">#</a> JDK</h2> <blockquote><p>从Java源码中提取的所有注解</p></blockquote> <table><thead><tr><th>注解</th> <th>版本</th> <th>说明</th></tr></thead> <tbody><tr><td>@WebParam</td> <td></td> <td>表示方法的参数</td></tr> <tr><td>@Oneway</td> <td></td> <td>表示为只有输入消息而没有输出消息的 Web Service 单向操作</td></tr> <tr><td>@WebResult</td> <td></td> <td>表示方法的返回值</td></tr> <tr><td>@HandlerChain</td> <td></td> <td>使 Web Service 与外部定义的处理程序链相关联。</td></tr> <tr><td>@WebService</td> <td></td> <td>用于对接口，类进行注解，表示要发布的web服务</td></tr> <tr><td>@WebMethod</td> <td></td> <td>该注解用于用@WebService注解的类或接口的方法上，表示要发布的方法</td></tr> <tr><td>@SOAPMessageHandlers</td> <td></td> <td></td></tr> <tr><td>@SOAPMessageHandler</td> <td></td> <td></td></tr> <tr><td>@SOAPBinding</td> <td></td> <td>SOAP绑定类型：RPC、DOCUMENT</td></tr> <tr><td>@InitParam</td> <td></td> <td></td></tr> <tr><td>@Resource</td> <td></td> <td></td></tr> <tr><td>@Resources</td> <td></td> <td></td></tr> <tr><td>@PreDestroy</td> <td>Servlet2.5</td> <td>被@PreDestroy修饰的方法会在服务器卸载Servlet之前运行，并且只会被服务器调用一次</td></tr> <tr><td>@Generated</td> <td></td> <td></td></tr> <tr><td>@PostConstruct</td> <td>Servlet2.5</td> <td>被@PostConstruct修饰的方法会在服务器加载Servle且构造函数之后执行，并且只会被服务器执行一次</td></tr> <tr><td>@RespectBinding</td> <td></td> <td></td></tr> <tr><td>@ResponseWrapper</td> <td></td> <td></td></tr> <tr><td>@WebServiceRefs</td> <td></td> <td></td></tr> <tr><td>@Action</td> <td></td> <td></td></tr> <tr><td>@RequestWrapper</td> <td></td> <td></td></tr> <tr><td>@WebServiceProvider</td> <td></td> <td></td></tr> <tr><td>@WebServiceRef</td> <td></td> <td></td></tr> <tr><td>@FaultAction</td> <td></td> <td></td></tr> <tr><td>@WebFault</td> <td></td> <td></td></tr> <tr><td>@ServiceMode</td> <td></td> <td></td></tr> <tr><td>@WebEndpoint</td> <td></td> <td></td></tr> <tr><td>@BindingType</td> <td></td> <td></td></tr> <tr><td>@WebServiceClient</td> <td></td> <td></td></tr> <tr><td>@Addressing</td> <td></td> <td></td></tr> <tr><td>@MTOM</td> <td></td> <td></td></tr> <tr><td>@WebServiceFeatureAnnotation</td> <td></td> <td></td></tr> <tr><td>@XmlSeeAlso</td> <td></td> <td></td></tr> <tr><td>@XmlElementDecl</td> <td></td> <td></td></tr> <tr><td>@XmlIDREF</td> <td></td> <td></td></tr> <tr><td>@XmlValue</td> <td></td> <td></td></tr> <tr><td>@XmlAccessorType</td> <td></td> <td>控制字段或属性的序列化</td></tr> <tr><td>@XmlMixed</td> <td></td> <td></td></tr> <tr><td>@XmlID</td> <td></td> <td></td></tr> <tr><td>@XmlRootElement</td> <td></td> <td>根节点,将Java类或枚举类型映射到XML元素</td></tr> <tr><td>@XmlElementRef</td> <td></td> <td></td></tr> <tr><td>@XmlEnum</td> <td></td> <td></td></tr> <tr><td>@XmlElementWrapper</td> <td></td> <td>对于数组或集合（即包含多个元素的成员变量），生成一个包装该数组或集合的XML元素（称为包装器）</td></tr> <tr><td>@XmlEnumValue</td> <td></td> <td></td></tr> <tr><td>@XmlType</td> <td></td> <td>对于@XmlElementWrapper标注的属性，不能出现在@XmlType的propOrder列表中</td></tr> <tr><td>@XmlAccessorOrder</td> <td></td> <td>控制JAXB 绑定类中属性和字段的排序</td></tr> <tr><td>@XmlSchemaTypes</td> <td></td> <td></td></tr> <tr><td>@XmlInlineBinaryData</td> <td></td> <td></td></tr> <tr><td>@XmlSchema</td> <td></td> <td></td></tr> <tr><td>@XmlAnyElement</td> <td></td> <td></td></tr> <tr><td>@XmlSchemaType</td> <td></td> <td></td></tr> <tr><td>@XmlRegistry</td> <td></td> <td></td></tr> <tr><td>@XmlList</td> <td></td> <td></td></tr> <tr><td>@XmlAttribute</td> <td></td> <td>将Java类的一个属性映射到与属性同名的一个XML元素</td></tr> <tr><td>@XmlAttachmentRef</td> <td></td> <td></td></tr> <tr><td>@XmlNs</td> <td></td> <td></td></tr> <tr><td>@XmlMimeType</td> <td></td> <td></td></tr> <tr><td>@XmlElements</td> <td></td> <td></td></tr> <tr><td>@XmlElement</td> <td></td> <td>对于所有@XmlElement标注过的属性，必须出现在@XmlType的propOrder列表中</td></tr> <tr><td>@XmlElementRefs</td> <td></td> <td></td></tr> <tr><td>@XmlTransient</td> <td></td> <td></td></tr> <tr><td>@XmlAnyAttribute</td> <td></td> <td></td></tr> <tr><td>@XmlJavaTypeAdapters</td> <td></td> <td></td></tr> <tr><td>@XmlJavaTypeAdapter</td> <td></td> <td>使用定制的适配器（即扩展抽象类XmlAdapter并覆盖marshal()和unmarshal()方法），以序列化Java类为XML</td></tr> <tr><td>@Interned</td> <td></td> <td></td></tr> <tr><td>@NotNull</td> <td></td> <td></td></tr> <tr><td>@Nullable</td> <td></td> <td></td></tr> <tr><td>@MessageDumping</td> <td></td> <td></td></tr> <tr><td>@FeatureConstructor</td> <td></td> <td></td></tr> <tr><td>@FeatureListValidatorAnnotation</td> <td></td> <td></td></tr> <tr><td>@InstanceResolverAnnotation</td> <td></td> <td></td></tr> <tr><td>@SchemaValidation</td> <td></td> <td></td></tr> <tr><td>@Serialization</td> <td></td> <td></td></tr> <tr><td>@StreamingAttachment</td> <td></td> <td></td></tr> <tr><td>@UsesJAXBContext</td> <td></td> <td></td></tr> <tr><td>@MemberSubmissionAddressing</td> <td></td> <td></td></tr> <tr><td>@XmlAccessorFactory</td> <td></td> <td></td></tr> <tr><td>@OverrideAnnotationOf</td> <td></td> <td></td></tr> <tr><td>@XmlIsSet</td> <td></td> <td></td></tr> <tr><td>@XmlLocation</td> <td></td> <td></td></tr> <tr><td>@WsgenProtocol</td> <td></td> <td></td></tr> <tr><td>@InheritedAttributes</td> <td></td> <td></td></tr> <tr><td>@DescriptorFields</td> <td></td> <td></td></tr> <tr><td>@ParameterNames</td> <td></td> <td></td></tr> <tr><td>@ManagedAttribute</td> <td></td> <td></td></tr> <tr><td>@AMXMetadata</td> <td></td> <td></td></tr> <tr><td>@InheritedAttribute</td> <td></td> <td></td></tr> <tr><td>@IncludeSubclass</td> <td></td> <td></td></tr> <tr><td>@ManagedData</td> <td></td> <td></td></tr> <tr><td>@ManagedOperation</td> <td></td> <td></td></tr> <tr><td>@Description</td> <td></td> <td></td></tr> <tr><td>@NameValue</td> <td></td> <td></td></tr> <tr><td>@ManagedObject</td> <td></td> <td></td></tr> <tr><td>@DescriptorKey</td> <td></td> <td></td></tr> <tr><td>@Taxonomy</td> <td></td> <td></td></tr> <tr><td>@Reset</td> <td></td> <td></td></tr> <tr><td>@ProbeParam</td> <td></td> <td></td></tr> <tr><td>@ProbeProvider</td> <td></td> <td></td></tr> <tr><td>@Probe</td> <td></td> <td></td></tr> <tr><td>@ProbeListener</td> <td></td> <td></td></tr> <tr><td>@EnvelopeStyle</td> <td></td> <td></td></tr> <tr><td>@Property</td> <td></td> <td></td></tr> <tr><td>@DatabindingMode</td> <td></td> <td></td></tr> <tr><td>@Reference</td> <td></td> <td></td></tr> <tr><td>@Immutable</td> <td></td> <td></td></tr> <tr><td>@Ignore</td> <td></td> <td></td></tr> <tr><td>@Logger</td> <td></td> <td></td></tr> <tr><td>@Setter</td> <td></td> <td></td></tr> <tr><td>@Constructor</td> <td></td> <td></td></tr> <tr><td>@Optimistic</td> <td></td> <td></td></tr> <tr><td>@SpecializedFunction</td> <td></td> <td></td></tr> <tr><td>@ScriptClass</td> <td></td> <td></td></tr> <tr><td>@Function</td> <td></td> <td></td></tr> <tr><td>@Getter</td> <td></td> <td></td></tr> <tr><td>@CallerSensitive</td> <td></td> <td></td></tr> <tr><td>@Contended</td> <td></td> <td></td></tr> <tr><td>@MXBean</td> <td></td> <td></td></tr> <tr><td>@ProbeName</td> <td></td> <td></td></tr> <tr><td>@ProviderName</td> <td></td> <td></td></tr> <tr><td>@Attributes</td> <td></td> <td></td></tr> <tr><td>@NameAttributes</td> <td></td> <td></td></tr> <tr><td>@ProviderAttributes</td> <td></td> <td></td></tr> <tr><td>@FunctionAttributes</td> <td></td> <td></td></tr> <tr><td>@ModuleName</td> <td></td> <td></td></tr> <tr><td>@ModuleAttributes</td> <td></td> <td></td></tr> <tr><td>@ArgsAttributes</td> <td></td> <td></td></tr> <tr><td>@FunctionName</td> <td></td> <td></td></tr> <tr><td>@ConstructorProperties</td> <td></td> <td></td></tr> <tr><td>@Transient</td> <td></td> <td></td></tr> <tr><td>@Deprecated</td> <td>jdk1.5</td> <td>内置注解：用于标志过时的类、方法和成员变量</td></tr> <tr><td>@FunctionalInterface</td> <td>jdk1.8</td> <td>函数式接口注解，用于定义函数式接口</td></tr> <tr><td>@SafeVarargs</td> <td>jdk1.7</td> <td>参数安全类型注解，用于提示用户参数安全</td></tr> <tr><td>@Override</td> <td>jdk1.5</td> <td>内置注解：用于修饰重写的方法</td></tr> <tr><td>@SuppressWarnings</td> <td>jdk1.5</td> <td>内置注解：用户忽略@Deprecated标志过的警告</td></tr> <tr><td>@Repeatable</td> <td>jdk1.8</td> <td>表示注解的属性可以重复！@Repeatable通俗来讲，就是注解容器！</td></tr> <tr><td>@Inherited</td> <td>jdk1.5</td> <td>元注解：子类继承父类的注解（子类没有任何注解修饰）</td></tr> <tr><td>@Retention</td> <td>jdk1.5</td> <td>元注解：表示注解保留周期</td></tr> <tr><td>@Documented</td> <td>jdk1.5</td> <td>元注解：将注解写入文档</td></tr> <tr><td>@Target</td> <td>jdk1.5</td> <td>元注解：表示注解可以使用在什么地方</td></tr> <tr><td>@Native</td> <td>jdk1.8</td> <td>生成本机头文件的工具的提示，以确定是否需要头文件，如果需要，它应该包含哪些声明。</td></tr> <tr><td>@Validate</td> <td></td> <td></td></tr> <tr><td>@RequireContainer</td> <td></td> <td></td></tr> <tr><td>@Require</td> <td></td> <td></td></tr> <tr><td>@Exported</td> <td></td> <td></td></tr> <tr><td>@SupportedOptions</td> <td></td> <td></td></tr> <tr><td>@SupportedAnnotationTypes</td> <td></td> <td></td></tr> <tr><td>@SupportedSourceVersion</td> <td></td> <td></td></tr> <tr><td>@Trusted</td> <td></td> <td></td></tr></tbody></table> <h2 id="servlet"><a href="#servlet" class="header-anchor">#</a> Servlet</h2> <blockquote><p><code>Tomcat 7.0</code>及以上版本的<code>server.api</code>才有注解</p></blockquote> <ul><li><code>servlet.jar</code> 是<code>servlet 3.0</code>版本之前的地址</li> <li><code>javax.servlet-api.jar</code> 是<code>servlet 3.0</code>版本之后的地址</li></ul> <ul><li><a href="https://github.com/eclipse-ee4j/servlet-api" target="_blank" rel="noopener noreferrer">https://github.com/eclipse-ee4j/servlet-api<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <table><thead><tr><th>注解</th> <th>版本</th> <th>说明</th></tr></thead> <tbody><tr><td>@WebServlet</td> <td>Servlet3.0</td> <td>用于声明servlet</td></tr> <tr><td>@WebListener</td> <td>Servlet3.0</td> <td>用于声明过监听器，可通过控制filter的文件名来控制执行顺序</td></tr> <tr><td>@WebFilter</td> <td>Servlet3.0</td> <td>用于声明过滤器</td></tr> <tr><td>@WebInitParam</td> <td>Servlet3.0</td> <td>为 Servlet 或者过滤器指定初始化参数，配置@WebServlet或@WebFilter时使用</td></tr> <tr><td>@MultipartConfig</td> <td>Servlet3.0</td> <td>HttpServletRequest 提供的对上传文件的支持，该注解标注在 Servlet 上面</td></tr> <tr><td>@HandlesTypes</td> <td></td> <td></td></tr> <tr><td>@HttpConstraint</td> <td></td> <td></td></tr> <tr><td>@HttpMethodConstraint</td> <td></td> <td></td></tr> <tr><td>@ServletSecurity</td> <td></td> <td></td></tr></tbody></table> <h2 id="validation"><a href="#validation" class="header-anchor">#</a> Validation</h2> <blockquote><p><code>JSR-303</code>是<code>JAVA EE 6</code>中的一项子规范，叫做<code>Bean Validation</code>，但是这只是一个接口，没有具体实现。</p></blockquote> <ul><li><a href="https://github.com/topics/validation" target="_blank" rel="noopener noreferrer">https://github.com/topics/validation<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/topics/validator" target="_blank" rel="noopener noreferrer">https://github.com/topics/validator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <ul><li><a href="https://github.com/apache/bval" target="_blank" rel="noopener noreferrer">https://github.com/apache/bval<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/hibernate/hibernate-validator" target="_blank" rel="noopener noreferrer">https://github.com/hibernate/hibernate-validator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://github.com/neoremind/fluent-validator" target="_blank" rel="noopener noreferrer">https://github.com/neoremind/fluent-validator<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <blockquote><p><code>javax.validation.Validation</code>、<code>hibernate-validator</code>和<code>Spring validtor</code>
提供了<code>JSR 303</code>规范中所有内置constraint 的实现，除此之外还有一些附加的 constraint</p></blockquote> <ul><li><a href="https://beanvalidation.org" target="_blank" rel="noopener noreferrer">https://beanvalidation.org<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://juejin.im/post/5d3fbeb46fb9a06b317b3c48" target="_blank" rel="noopener noreferrer">这么写参数校验(validator)就不会被劝退了<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li><a href="https://blog.csdn.net/king101125s/article/details/104356059" target="_blank" rel="noopener noreferrer">四款数据校验的类(Validate)<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <table><thead><tr><th>注解</th> <th>支持Java类型</th> <th>备注</th></tr></thead> <tbody><tr><td>@AssertFalse</td> <td>Boolean, boolean</td> <td>验证元素值必须为flase</td></tr> <tr><td>@AssertTrue</td> <td>Boolean, boolean</td> <td>验证元素值必须为true，否则抛异常</td></tr> <tr><td>@CreditCardNumber</td> <td>CharSequence</td> <td>验证信用卡号码是否有效</td></tr> <tr><td>@DecimalMax</td> <td>Object</td> <td>验证数值是否小于等于指定值</td></tr> <tr><td>@DecimalMin</td> <td>CharSequence</td> <td>验证数值是否大于等于指定值</td></tr> <tr><td>@Digits(integer = 3, fraction = 2)</td> <td>Long, Integer, Double, Float</td> <td>验证注解的元素值的整数位数和小数位数上限</td></tr> <tr><td>@Email</td> <td>CharSequence</td> <td>验证元素必须是电子邮箱地址</td></tr> <tr><td>@Future</td> <td>java.util.Date, java.util.Calendar</td> <td>验证日期为当前时间之后</td></tr> <tr><td>@FutureOrPresent</td> <td>java.util.Date, java.util.Calendar</td> <td>验证日期为当前时间或之后一个时间</td></tr> <tr><td>@Length(min=,max=)</td> <td>CharSequence</td> <td>验证元素值包含在一个区间</td></tr> <tr><td>@Max</td> <td>CharSequence</td> <td>检验当前数值小于等于指定值</td></tr> <tr><td>@Min</td> <td>BigDecimal, BigInteger, byte, short,int, long,Number.</td> <td>检验当前数值大于等于指定值</td></tr> <tr><td>@NotBlank</td> <td>CharSequence</td> <td>验证元素值不为null且移除两边空格后长度大于0</td></tr> <tr><td>@NotEmpty</td> <td>CharSequence,Collection,Map and Arrays</td> <td>验证元素值不为null且不为空（字符串长度不为0、集合大小不为0）</td></tr> <tr><td>@NotNull</td> <td>Object</td> <td>验证元素值不能为 null</td></tr> <tr><td>@Null</td> <td>Object</td> <td>验证元素值为null</td></tr> <tr><td>@Past</td> <td>java.util.Date, java.util.Calendar</td> <td>验证日期为当前时间之前</td></tr> <tr><td>@PastOrPresent</td> <td>java.util.Date, java.util.Calendar</td> <td>验证日期为当前时间或之前</td></tr> <tr><td>@Pattern(regex=,flag=)</td> <td>CharSequence</td> <td>验证元素必须符合指定的正则表达式</td></tr> <tr><td>@Range(min=,max=,message=)</td> <td>CharSequence</td> <td>验证数值为指定值区间范围内</td></tr> <tr><td>@Size(max=, min=)</td> <td>String,Collection,Map,arrays,CharSequence</td> <td>验证元素个数包含在一个区间</td></tr> <tr><td>@UniqueElements</td> <td>Collection</td> <td>校验集合中的元素必须保持唯一 否则异常</td></tr> <tr><td>@URL</td> <td>CharSequence</td> <td>验证日期为当前时间之前</td></tr> <tr><td>@Valid</td> <td>Object</td> <td>验证关联对象元素进行递归校验检查</td></tr> <tr><td>@ScriptAssert</td> <td>CharSequence</td> <td>脚本表达式的计算结果为true</td></tr> <tr><td>@SafeHtml</td> <td>CharSequence</td> <td>可能包含不安全的html内容</td></tr></tbody></table> <h2 id="jax-rs"><a href="#jax-rs" class="header-anchor">#</a> JAX-RS</h2> <blockquote><p><code>Jersey</code>和<code>CxF</code>框架实现了<code>JSR311</code>/<code>JSR339</code>标准</p></blockquote> <p><strong>jersey常用注解</strong></p> <ul><li><a href="https://github.com/eclipse-ee4j/jersey" target="_blank" rel="noopener noreferrer">https://github.com/eclipse-ee4j/jersey<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul> <table><thead><tr><th>Annotation</th> <th>作用</th> <th>说明</th></tr></thead> <tbody><tr><td>@GET</td> <td>查询请求</td> <td>相当于数据库的查询数据操作</td></tr> <tr><td>@PUT</td> <td>更新请求</td> <td>相当于数据库的更新数据操作</td></tr> <tr><td>@POST</td> <td>插入请求</td> <td>相当于数据库的插入数据操作</td></tr> <tr><td>@DELETE</td> <td>删除请求</td> <td>相当于数据的删除数据操作</td></tr> <tr><td>@Path</td> <td>uri路径</td> <td>定义资源的访问路径，client通过这个路径访问资源。比如：@Path(&quot;user&quot;)</td></tr> <tr><td>@Produces</td> <td>指定返回MIME格式</td> <td>资源按照那种数据格式返回，可取的值有：MediaType.APPLICATION_XXX。比如：@Produces(MediaType.APPLICATION_XML)</td></tr> <tr><td>@Consumes</td> <td>接受指定的MIME格式</td> <td>只有符合这个参数设置的请求再能访问到这个资源。比如@Consumes(&quot;application/x-www-form-urlencoded&quot;)</td></tr> <tr><td>@PathParam</td> <td>uri路径参数</td> <td>写在方法的参数中，获得请求路径参数。比如：@PathParam(&quot;username&quot;) String userName</td></tr> <tr><td>@QueryParam</td> <td>uri路径请求参数</td> <td>写在方法的参数中，获得请求路径附带的参数。比如：@QueryParam(&quot;desc&quot;) String desc</td></tr> <tr><td>@DefaultValue</td> <td>设置@QueryParam参数的默认值</td> <td>如果@QueryParam没有接收到值，就使用默认值。比如：@DefaultValue(&quot;description&quot;) @QueryParam(&quot;desc&quot;) String desc</td></tr> <tr><td>@FormParam</td> <td>form传递的参数</td> <td>接受form传递过来的参数。比如：@FormParam(&quot;name&quot;) String userName</td></tr> <tr><td>@BeanParam</td> <td>通过Bean的形式传递参数</td> <td>接受client传递的bean类型的参数，同时这个bean可以在属性上配置@FormParam用以解决client的属性名称和bean的属性名称不一致的问题。比如：@BeanParam User user</td></tr> <tr><td>@Context</td> <td>获得一些系统环境信息</td> <td>通过@Context可以获得以下信息：UriInfo、ServletConfig、ServletContext、HttpServletRequest、HttpServletResponse和HttpHeaders等</td></tr></tbody></table> <h2 id="spring"><a href="#spring" class="header-anchor">#</a> Spring</h2> <h3 id="声明bean的注解"><a href="#声明bean的注解" class="header-anchor">#</a> 声明bean的注解</h3> <ul><li><code>@Component</code> 组件，没有明确的角色</li> <li><code>@Service</code> 在业务逻辑层使用（service层）</li> <li><code>@Repository</code> 在数据访问层使用（dao层）</li> <li><code>@Controller</code> 在展现层使用，控制器的声明（C）</li></ul> <h3 id="注入bean的注解"><a href="#注入bean的注解" class="header-anchor">#</a> 注入bean的注解</h3> <blockquote><p>都可以注解在set方法和属性上，推荐注解在属性上（一目了然，少写代码）。</p></blockquote> <ul><li><code>@Autowired</code> 由Spring提供（Spring上下文已有实例（已注入IOC），<code>@Autowired</code>只是取一下）</li> <li><code>@Inject</code> 由JSR-330提供</li> <li><code>@Resource</code> 由JSR-250提供</li></ul> <h3 id="java配置类相关注解"><a href="#java配置类相关注解" class="header-anchor">#</a> java配置类相关注解</h3> <ul><li><code>@Configuration</code> 声明当前类为配置类，相当于xml形式的Spring配置（类上）</li> <li><code>@Bean</code> 注解在方法上，声明当前方法的返回值为一个bean，替代xml中的方式（方法上）</li> <li><code>@Configuration</code> 声明当前类为配置类，其中内部组合了<code>@Component</code>注解，表明这个类是一个bean（类上）</li> <li><code>@ComponentScan</code> 用于对Component进行扫描，相当于xml中的（类上）</li> <li><code>@WishlyConfiguration</code> 为<code>@Configuration</code>与<code>@ComponentScan</code>的组合注解，可以替代这两个注解</li></ul> <h3 id="切面-aop-相关注解"><a href="#切面-aop-相关注解" class="header-anchor">#</a> 切面（AOP）相关注解</h3> <blockquote><p>Spring支持AspectJ的注解式切面编程。</p></blockquote> <ul><li><code>@Aspect</code> 声明一个切面（类上）</li></ul> <blockquote><p>使用<code>@After</code>、<code>@Before</code>、<code>@Around</code>定义建言（advice），可直接将拦截规则（切点）作为参数。</p></blockquote> <ul><li><code>@After</code> 在方法执行之后执行（方法上）</li> <li><code>@Before</code> 在方法执行之前执行（方法上）</li> <li><code>@Around</code> 在方法执行之前与之后执行（方法上）</li> <li><code>@PointCut</code> 声明切点</li></ul> <blockquote><p>在java配置类中使用<code>@EnableAspectJAutoProxy</code>注解开启Spring对AspectJ代理的支持（类上）</p></blockquote> <table><thead><tr><th>AOP配置元素</th> <th>描述</th></tr></thead> <tbody><tr><td><code>&lt;aop:advisor&gt;</code></td> <td>定义AOP通知器</td></tr> <tr><td><code>&lt;aop:after&gt;</code></td> <td>定义AOP后置通知（不管该方法是否执行成功）</td></tr> <tr><td><code>&lt;aop:after-returning&gt;</code></td> <td>在方法成功执行后调用通知</td></tr> <tr><td><code>&lt;aop:after-throwing&gt;</code></td> <td>在方法抛出异常后调用通知</td></tr> <tr><td><code>&lt;aop:around&gt;</code></td> <td>定义AOP环绕通知</td></tr> <tr><td><code>&lt;aop:aspect&gt;</code></td> <td>定义切面</td></tr> <tr><td><code>&lt;aop:aspect-autoproxy&gt;</code></td> <td>定义<code>@AspectJ</code>注解驱动的切面</td></tr> <tr><td><code>&lt;aop:before&gt;</code></td> <td>定义AOP前置通知</td></tr> <tr><td><code>&lt;aop:config&gt;</code></td> <td>顶层的AOP配置元素，大多数的<a href="aop:*">aop:*</a>包含在<a href="aop:config">aop:config</a>元素内</td></tr> <tr><td><code>&lt;aop:declare-parent&gt;</code></td> <td>为被通知的对象引入额外的接口，并透明的实现</td></tr> <tr><td><code>&lt;aop:pointcut&gt;</code></td> <td>定义切点</td></tr></tbody></table> <h3 id="bean的属性支持"><a href="#bean的属性支持" class="header-anchor">#</a> @Bean的属性支持</h3> <blockquote><p><code>@Bean</code> 手动创建一个实例，并保留在IOC中，当我们引用第三方库中的类需要装配到Spring容器时，可以通过<code>@Bean</code>来实现</p></blockquote> <ul><li><code>@Scope</code> 设置Spring容器如何新建Bean实例（方法上，得有<code>@Bean</code>）,其设置类型包括：
<ul><li><code>Singleton</code> （单例,一个Spring容器中只有一个bean实例，默认模式）,</li> <li><code>Protetype</code> （每次调用新建一个bean）,</li> <li><code>Request</code> （web项目中，给每个http request新建一个bean）,</li> <li><code>Session</code> （web项目中，给每个http session新建一个bean）,</li> <li><code>GlobalSession</code>（给每一个 global http session新建一个Bean实例）</li></ul></li> <li><code>@StepScope</code> 在Spring Batch中还有涉及</li> <li><code>@PostConstruct</code> 由JSR-250提供，在构造函数执行完之后执行，等价于xml配置文件中bean的initMethod</li> <li><code>@PreDestory</code> 由JSR-250提供，在Bean销毁之前执行，等价于xml配置文件中bean的destroyMethod</li></ul> <h3 id="value注解"><a href="#value注解" class="header-anchor">#</a> @Value注解</h3> <blockquote><p><code>@Value</code> 为属性注入值（属性上）</p></blockquote> <ul><li><code>@Value(&quot;Michael Jackson&quot;)</code> String name; 注入普通字符</li> <li><code>@Value(&quot;#{systemProperties['os.name']}&quot;)</code> String osName; 注入操作系统属性</li> <li><code>@Value(&quot;#{ T(java.lang.Math).random() * 100 }&quot;)</code> String randomNumber; 注入表达式结果</li> <li><code>@Value(&quot;#{domeClass.name}&quot;)</code> String name; 注入其它bean属性</li> <li><code>@Value(&quot;classpath:com/hgs/hello/test.txt&quot;)</code> String Resource file; 注入文件资源</li> <li><code>@Value(&quot;http://www.cznovel.com&quot;)</code> Resource url; 注入网站资源</li> <li><code>@Value(&quot;${book.name}&quot;)</code> String bookName; 注入配置文件</li></ul> <p><strong>注入配置使用方法</strong></p> <blockquote><p>编写配置文件（test.properties）</p></blockquote> <div class="language-conf extra-class"><pre class="language-text"><code>book.name = test
</code></pre></div><ul><li><code>@PropertySource</code> 加载配置文件(类上)</li></ul> <div class="language-java extra-class"><pre class="language-java"><code><span class="token annotation punctuation">@PropertySource</span><span class="token punctuation">(</span><span class="token string">&quot;classpath:/test.propertie&quot;</span><span class="token punctuation">)</span>
</code></pre></div><ul><li>还需配置一个<code>PropertySourcesPlaceholderConfigurer</code>的bean。</li></ul> <h3 id="环境切换"><a href="#环境切换" class="header-anchor">#</a> 环境切换</h3> <ul><li><code>@Profile</code> 通过设定Environment的ActiveProfiles来设定当前context需要使用的配置环境。（类或方法上）</li> <li><code>@Conditional</code> Spring4中可以使用此注解定义条件话的bean，通过实现Condition接口，并重写matches方法，从而决定该bean是否被实例化。（方法上）</li></ul> <h3 id="异步相关"><a href="#异步相关" class="header-anchor">#</a> 异步相关</h3> <ul><li><code>@EnableAsync</code> 配置类中，通过此注解开启对异步任务的支持，叙事性AsyncConfigurer接口（类上）</li> <li><code>@Async</code> 在实际执行的bean方法使用该注解来申明其是一个异步任务（方法上或类上所有的方法都将异步，需要@EnableAsync开启异步任务）</li></ul> <h3 id="定时任务相关"><a href="#定时任务相关" class="header-anchor">#</a> 定时任务相关</h3> <ul><li><code>@EnableScheduling</code> 在配置类上使用，开启计划任务的支持（类上）</li> <li><code>@Scheduled</code> 来申明这是一个任务，包括cron,fixDelay,fixRate等类型（方法上，需先开启计划任务的支持）</li></ul> <h3 id="enable-注解说明"><a href="#enable-注解说明" class="header-anchor">#</a> @Enable*注解说明</h3> <blockquote><p>这些注解主要用来开启对xxx的支持。</p></blockquote> <ul><li><code>@EnableAspectJAutoProxy</code> 开启对AspectJ自动代理的支持</li> <li><code>@EnableAsync</code> 开启异步方法的支持</li> <li><code>@EnableScheduling</code> 开启计划任务的支持</li> <li><code>@EnableWebMvc</code> 开启Web MVC的配置支持</li> <li><code>@EnableConfigurationProperties</code> 开启对<code>@ConfigurationProperties</code>注解配置Bean的支持</li> <li><code>@EnableJpaRepositories</code> 开启对SpringData JPA Repository的支持</li> <li><code>@EnableTransactionManagement</code> 开启注解式事务的支持</li> <li><code>@EnableTransactionManagement</code> 开启注解式事务的支持</li> <li><code>@EnableCaching</code> 开启注解式的缓存支持</li></ul> <h3 id="测试相关注解"><a href="#测试相关注解" class="header-anchor">#</a> 测试相关注解</h3> <ul><li><code>@RunWith</code> 运行器，Spring中通常用于对JUnit的支持 <code>@RunWith(SpringJUnit4ClassRunner.class)</code></li> <li><code>@ContextConfiguration</code> 用来加载配置ApplicationContext，其中classes属性用来加载配置类 <code>@ContextConfiguration(classes={TestConfig.class})</code></li> <li><code>@WebAppConfiguration</code></li></ul> <h3 id="springmvc注解"><a href="#springmvc注解" class="header-anchor">#</a> SpringMVC注解</h3> <ul><li><code>@EnableWebMvc</code> 在配置类中开启Web MVC的配置支持，如一些ViewResolver或者MessageConverter等，若无此句，重写WebMvcConfigurerAdapter方法（用于对SpringMVC的配置）。</li> <li><code>@Controller</code> 声明该类为SpringMVC中的Controller</li> <li><code>@RequestMapping</code> 用于映射Web请求，包括访问路径和参数（类或方法上）</li> <li><code>@ResponseBody</code> 支持将返回值放在response内，而不是一个页面，通常用户返回json数据（返回值旁或方法上）</li> <li><code>@RequestBody</code> 允许request的参数在request体中，而不是在直接连接在地址后面。（放在参数前）</li> <li><code>@PathVariable</code> 用于接收路径上使用<code>{}</code>声明的参数，比如<code>@RequestMapping(“/hello/{name}”)</code>申明的路径，将注解放在参数中前，即可获取该值，通常作为Restful的接口实现方法。</li> <li><code>@RequestParam</code> 用于接收参数（在实际使用中，如果变量名与参数名相同可不使用此注解），<code>GET</code>为<code>?</code>后面的查询参数，<code>POST</code>为body中的表单参数；可与<code>@PathVariable</code>同时使用</li> <li><code>@RestController</code> 该注解为一个组合注解，相当于<code>@Controller</code>和<code>@ResponseBody</code>的组合，注解在类上，意味着，该Controller的所有方法都默认加上了<code>@ResponseBody</code>。</li> <li><code>@ControllerAdvice</code> 通过该注解，我们可以将对于控制器的全局配置放置在同一个位置，注解了<code>@Controller</code>的类的方法可使用
<code>@ExceptionHandler</code>、<code>@InitBinder</code>、<code>@ModelAttribute</code>注解到方法上，这对所有注解了 <code>@RequestMapping</code>的控制器内的方法有效。</li> <li><code>@ExceptionHandler</code> 用于全局处理控制器里的异常</li> <li><code>@InitBinder</code> 用来设置WebDataBinder，WebDataBinder用来自动绑定前台请求参数到Model中。</li> <li><code>@ModelAttribute</code> 本来的作用是绑定键值对到Model里，在<code>@ControllerAdvice</code>中是让全局的<code>@RequestMapping</code>都能获得在此处设置的键值对。</li></ul> <h2 id="swagger2"><a href="#swagger2" class="header-anchor">#</a> Swagger2</h2> <table><thead><tr><th>注解名称</th> <th>注解属性</th> <th>作用域</th> <th>属性作用</th></tr></thead> <tbody><tr><td>@Api</td> <td>tags</td> <td>类</td> <td>说明该类的作用</td></tr> <tr><td></td> <td>value</td> <td>类</td> <td>说明该类的作用</td></tr> <tr><td>@ApiOperation()</td> <td>value</td> <td>方法</td> <td>描述方法作用</td></tr> <tr><td></td> <td>notes</td> <td>方法</td> <td>提示内容</td></tr> <tr><td></td> <td>tags</td> <td>方法</td> <td>分组</td></tr> <tr><td>@ApiParam()</td> <td>name</td> <td>方法参数</td> <td>参数名</td></tr> <tr><td></td> <td>value</td> <td>方法参数</td> <td>参数说明</td></tr> <tr><td></td> <td>required</td> <td>方法参数</td> <td>是否必填</td></tr> <tr><td>@ApiModel()</td> <td>value</td> <td>类</td> <td>对象名</td></tr> <tr><td></td> <td>description</td> <td>类</td> <td>描述</td></tr> <tr><td>@ApiModelProperty()</td> <td>value</td> <td>方法</td> <td>字段说明</td></tr> <tr><td></td> <td>name</td> <td>方法</td> <td>属性名</td></tr> <tr><td></td> <td>dataType</td> <td>方法</td> <td>属性类型</td></tr> <tr><td></td> <td>required</td> <td>方法</td> <td>是否必填</td></tr> <tr><td></td> <td>example</td> <td>方法</td> <td>举例</td></tr> <tr><td></td> <td>hidden</td> <td>方法</td> <td>隐藏</td></tr> <tr><td>@ApiImplicitParam()</td> <td>value</td> <td>方法</td> <td>参数说明</td></tr> <tr><td></td> <td>name</td> <td>方法</td> <td>参数名</td></tr> <tr><td></td> <td>dataType</td> <td>方法</td> <td>数据类型</td></tr> <tr><td></td> <td>paramType</td> <td>方法</td> <td>参数类型</td></tr> <tr><td></td> <td>example</td> <td>方法</td> <td>举例</td></tr> <tr><td>@ApiResponse()</td> <td>response</td> <td>方法</td> <td>返回类</td></tr> <tr><td></td> <td>code</td> <td>方法</td> <td>返回码</td></tr> <tr><td></td> <td>message</td> <td>方法</td> <td>返回信息</td></tr> <tr><td></td> <td>examples</td> <td>方法</td> <td>例子</td></tr></tbody></table> <table><thead><tr><th>注解</th> <th>属性</th> <th>值</th> <th>备注</th></tr></thead> <tbody><tr><td>@Api</td> <td>value</td> <td>字符串</td> <td>可用在class头上,class描述</td></tr> <tr><td></td> <td>description</td> <td>字符串</td> <td></td></tr> <tr><td></td> <td></td> <td></td> <td>@Api(value = &quot;xxx&quot;, description = &quot;xxx&quot;)</td></tr> <tr><td>@ApiOperation</td> <td>value</td> <td>字符串</td> <td>可用在方法头上.参数的描述容器</td></tr> <tr><td></td> <td>notes</td> <td>字符串</td> <td></td></tr> <tr><td></td> <td></td> <td></td> <td>@ApiOperation(value = &quot;xxx&quot;, notes = &quot;xxx&quot;)</td></tr> <tr><td>@ApiImplicitParams</td> <td>{}</td> <td>@ApiImplicitParam数组</td> <td>可用在方法头上.参数的描述容器</td></tr> <tr><td></td> <td></td> <td></td> <td>@ApiImplicitParams({@ApiImplicitParam1,@ApiImplicitParam2,...})</td></tr> <tr><td>@ApiImplicitParam</td> <td>name</td> <td>字符串 与参数命名对应</td> <td>可用在@ApiImplicitParams里</td></tr> <tr><td></td> <td>value</td> <td>字符串</td> <td>参数中文描述</td></tr> <tr><td></td> <td>required</td> <td>布尔值</td> <td>true/false</td></tr> <tr><td></td> <td>dataType</td> <td>字符串</td> <td>参数类型</td></tr> <tr><td></td> <td>paramType</td> <td>字符串</td> <td>参数请求方式:query/path</td></tr> <tr><td></td> <td></td> <td></td> <td>query:对应@RequestParam?传递</td></tr> <tr><td></td> <td></td> <td></td> <td>path: 对应@PathVariable{}path传递</td></tr> <tr><td></td> <td>defaultValue</td> <td>字符串</td> <td>在api测试中默认值</td></tr> <tr><td></td> <td></td> <td></td> <td>用例参见项目中的设置</td></tr> <tr><td>@ApiResponses</td> <td>{}</td> <td>@ApiResponse数组</td> <td>可用在方法头上.参数的描述容器</td></tr> <tr><td></td> <td></td> <td></td> <td>@ApiResponses({@ApiResponse1,@ApiResponse2,...})</td></tr> <tr><td>@ApiResponse</td> <td>code</td> <td>整形</td> <td>可用在@ApiResponses里</td></tr> <tr><td></td> <td>message</td> <td>字符串</td> <td>错误描述</td></tr> <tr><td></td> <td></td> <td></td> <td>@ApiResponse(code = 200, message = &quot;Successful&quot;)</td></tr></tbody></table> <h2 id="jackson"><a href="#jackson" class="header-anchor">#</a> Jackson</h2> <table><thead><tr><th>注解名称</th> <th>作用域</th> <th>说明</th></tr></thead> <tbody><tr><td>@JacksonAnnotation</td> <td></td> <td></td></tr> <tr><td>@JacksonAnnotationsInside</td> <td></td> <td></td></tr> <tr><td>@JacksonAnnotationValue</td> <td></td> <td></td></tr> <tr><td>@JacksonInject</td> <td></td> <td></td></tr> <tr><td>@JsonAlias</td> <td></td> <td></td></tr> <tr><td>@JsonAnyGetter</td> <td></td> <td></td></tr> <tr><td>@JsonAnySetter</td> <td></td> <td></td></tr> <tr><td>@JsonAutoDetect</td> <td></td> <td></td></tr> <tr><td>@JsonBackReference</td> <td></td> <td></td></tr> <tr><td>@JsonClassDescription</td> <td></td> <td></td></tr> <tr><td>@JsonCreator</td> <td></td> <td></td></tr> <tr><td>@JsonEnumDefaultValue</td> <td></td> <td></td></tr> <tr><td>@JsonFilter</td> <td></td> <td></td></tr> <tr><td>@JsonFormat</td> <td></td> <td>格式化</td></tr> <tr><td>@JsonGetter</td> <td></td> <td></td></tr> <tr><td>@JsonIdentityInfo</td> <td></td> <td></td></tr> <tr><td>@JsonIdentityReference</td> <td></td> <td></td></tr> <tr><td>@JsonIgnore</td> <td></td> <td></td></tr> <tr><td>@JsonIgnoreProperties</td> <td></td> <td></td></tr> <tr><td>@JsonIgnoreType</td> <td></td> <td></td></tr> <tr><td>@JsonInclude</td> <td></td> <td></td></tr> <tr><td>@JsonManagedReference</td> <td></td> <td></td></tr> <tr><td>@JsonMerge</td> <td></td> <td></td></tr> <tr><td>@JsonProperty</td> <td></td> <td></td></tr> <tr><td>@JsonPropertyDescription</td> <td></td> <td></td></tr> <tr><td>@JsonPropertyOrder</td> <td></td> <td></td></tr> <tr><td>@JsonRawValue</td> <td></td> <td></td></tr> <tr><td>@JsonRootName</td> <td></td> <td></td></tr> <tr><td>@JsonSetter</td> <td></td> <td></td></tr> <tr><td>@JsonSubTypes</td> <td></td> <td></td></tr> <tr><td>@JsonTypeId</td> <td></td> <td></td></tr> <tr><td>@JsonTypeInfo</td> <td></td> <td></td></tr> <tr><td>@JsonTypeName</td> <td></td> <td></td></tr> <tr><td>@JsonUnwrapped</td> <td></td> <td></td></tr> <tr><td>@JsonValue</td> <td></td> <td></td></tr> <tr><td>@JsonView</td> <td></td> <td></td></tr></tbody></table></div> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/woytu/notes-vuepress/edit/master//Java/Annotation.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2021-07-15 19:52:20</span></div></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/Java/" class="prev router-link-active">
        Java
      </a></span> <span class="next"><a href="/Java/JDK安装配置.html">
        JDK安装配置
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.269009d6.js" defer></script><script src="/assets/js/3.974b9720.js" defer></script><script src="/assets/js/24.43e324e1.js" defer></script>
  </body>
</html>
